export = Point;


/**
 * 点
 * @author jackliu
 *
 */

class Point {
    // 点的类型
    public static POD_TT_PRIM_NONE :number       = 0;
    public static POD_TT_PRIM_LINE  :number      = 1;
    public static POD_TT_PRIM_QSPLINE :number    = 2;
    public static POD_TT_PRIM_CSPLINE :number    = 3;
    public static POD_TT_PRIM_MOVE  :number      = 8;
    public static POD_TT_PRIM_CLOSE  :number     = 9;
    
    // 属性
    public x:number=0;
    public y:number=0;
    public type:number=Point.POD_TT_PRIM_LINE;
    
    public constructor(x?:number,y?:number,type?:number) {
        if(typeof x !='undefined'){
            this.x=x;
        }
        if(typeof y!='undefined') {
            this.y=y;
        }
        if(typeof type!='undefined') {
            this.type=type;
        }
        
	}
	// copy
	public static copy(p:Point):Point{
        return new Point(p.x,p.y,p.type);
	}
	
    // point to array
    // point:"11,12,13"
    public toArray ():string{
        return '['+
            (this.x*1).toFixed(3)+','+ 
            (this.y*1).toFixed(3)+','+
            (this.type*1).toFixed(0)
            +']';
    }
    /**
    * 从数组中解析点
    * @param arr : 数组类型，存放x y t
    */
    public fromArray(arr){
        this.x=Point.removeZero(+arr[0]);
        this.y=Point.removeZero(+arr[1]);
        this.type=Point.removeZero(+arr[2]);
    }
    public fromJson(jsonObj, versionId) {
        this.x=jsonObj.x*1;
        this.y=jsonObj.y*1;
        this.type=jsonObj.type*1;
    }
    // 求长度［暂时不处理bezier曲线］
    public distance(pt:Point) { 
        return Math.sqrt(Math.pow(this.x-pt.x,2)+Math.pow(this.y-pt.y,2));
    }
    // 抹掉浮点数0后面多余的0
    // 参数：o浮点数
    public static removeZero(f: number): number {
        f = f*1;//将可能出现的string类型转换为number类型
        if(Number.isInteger(f)){
            return f;
        }
        return f.toFixed(3);
    }
    
//SJG_MARK_APPEND--------------------
    public newMethod(){
        
    }


}//SJG_MARK_END-------------------------